//
//  GameState.m
//  GameProject
//
//  Created by Blair Trusler on 17/10/2011.
//  Copyright (c) 2011 Blair Trusler. All rights reserved.
//

#import "GameHeader.h"

@implementation GameState

@synthesize achievement1;
@synthesize achievement2;
@synthesize achievement3;
@synthesize achievement4;
@synthesize achievement5;
@synthesize achievement6;
@synthesize achievement7;
@synthesize achievement8;
@synthesize achievement9;
@synthesize achievement10;

//@synthesize achievementOriginal;


static GameState *sharedInstance = nil;

+(GameState *) sharedInstance{
    @synchronized ([GameState class]){
        if (!sharedInstance){
            sharedInstance = [loadData(@"GameState") retain];
            if(!sharedInstance){
                [[self alloc]init];
            }
        }
        return sharedInstance;
    }
    return nil;
}

+(id) alloc{
    @synchronized ([GameState class]){
        NSAssert(sharedInstance == nil, @"Attempted to allocate a second instance of GameState singleton");
        
        sharedInstance = [super alloc];
        
        return sharedInstance;
    }
    return nil;
}

-(void)save{
    saveData(self, @"GameState");
}

-(void)encodeWithCoder:(NSCoder *)encoder{
    [encoder encodeBool:achievement1 forKey:@"achievement1"];
    [encoder encodeBool:achievement2 forKey:@"achievement2"];
    [encoder encodeBool:achievement3 forKey:@"achievement3"];
    [encoder encodeBool:achievement4 forKey:@"achievement4_level13stars"];
    [encoder encodeBool:achievement5 forKey:@"achievement5_level23stars"];
    [encoder encodeBool:achievement6 forKey:@"achievement6_level33stars"];
    [encoder encodeBool:achievement7 forKey:@"achievement7_gameover"];
    [encoder encodeBool:achievement8 forKey:@"achievement8_credits"];
    [encoder encodeBool:achievement9 forKey:@"achievement9_caught"];
    [encoder encodeBool:achievement10 forKey:@"achievement10_"];

}

-(id)initWithCoder:(NSCoder *)decoder{
    if ((self = [super init])){
        achievement1 = [decoder decodeBoolForKey:@"achievement1"];
        achievement2 = [decoder decodeBoolForKey:@"achievement2"];
        achievement3 = [decoder decodeBoolForKey:@"achievement3"];
        achievement4 = [decoder decodeBoolForKey:@"achievement4_level13stars"];
        achievement5 = [decoder decodeBoolForKey:@"achievement5_level23stars"];
        achievement6 = [decoder decodeBoolForKey:@"achievement6_level33stars"];
        achievement7 = [decoder decodeBoolForKey:@"achievement7_gameover"];
        achievement8 = [decoder decodeBoolForKey:@"achievement8_credits"];
        achievement9 = [decoder decodeBoolForKey:@"achievement9_caught"];
        achievement10 = [decoder decodeBoolForKey:@"achievement10_"];

        
        
//        achievementOriginal = [decoder decodeBoolForKey:@"achievementOriginal"];

    }
    return self;
}



@end
